package game;

import java.awt.*;

public class BaseElement {//作为所有元素的父类，提供显示、移动与相交判定三个方法

    protected int x, y;//坐标
    protected int width, height;//大小
    protected Image image;//绘制图像
    public void drawImage(Graphics g) {
        g.drawImage(this.image, this.x, this.y, this.width, this.height, null);
    }
    public Rectangle getRectangle() {
        return new Rectangle(this.x, this.y, this.width, this.height);
    }
    public <E extends BaseElement> boolean intersects(E element) {  //判断元素是否相交
        return this.getRectangle().intersects(element.getRectangle());
    }

    public void action() {
        this.xMove();
        this.yMove();
    }
    protected void xMove(){

    }

    protected void yMove(){

    }
}
